package com.gqh.weather.config;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

import lombok.extern.slf4j.Slf4j;

/**
 * @description MyBatis-Plus 字段自动填充处理器
 * @author AI
 * @date 2025-09-21
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入时自动填充
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        // 填充创建时间和更新时间
        Long currentTime = System.currentTimeMillis()/1000;

        this.strictInsertFill(metaObject, "createdTime", Long.class, currentTime);
        this.strictInsertFill(metaObject, "updatedTime", Long.class, currentTime);
    }

    /**
     * 更新时自动填充
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        // 填充更新时间
        Long currentTime = System.currentTimeMillis()/1000;

        this.strictUpdateFill(metaObject, "updatedTime", Long.class, currentTime);
    }
}